package com.sky.controller.user;

import com.sky.service.merchant.MerchantService;
import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.vo.ShopVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("userShopController")
@RequestMapping("/user/shop")
public class ShopController {

    public static final  String KEY = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private MerchantService merchantService;


    //用户获取店铺的营业状态
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        return Result.success(status);
    }

    //获取商家信息
    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result getMerchantInfo(){
        //获取唯一商家对象信息
       Merchant merchant = merchantService.getShopById(1l);
        String shopName = merchant.getShopName();
        String shopAddress = merchant.getShopAddress();
        String shopTelephone = merchant.getShopTelephone();
        ShopVO shopVO = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return Result.success(shopVO);
    }

}
